package com.sskj.gcc.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.gcc.bean.BannerBean;
import com.sskj.gcc.bean.ZixunListBean;
import com.sskj.gcc.http.HttpConfig;
import com.sskj.gcc.ui.activity.ZixunActivity;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;

public class ZixunActivityPresenter extends BasePresenter<ZixunActivity> {
    public Flowable<List<ZixunListBean>> getData(String page) {
        return OkGo.<HttpData<PageBean<ZixunListBean>>>post(HttpConfig.BASE_URL + HttpConfig.GET_ZIXUN_LIST)
                .params("p", page)
                .params("s", 20)
                .converter(new JsonConverter<HttpData<PageBean<ZixunListBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList());
    }

    public void getBanner(String type) {
        OkGo.<HttpData<List<BannerBean>>>get(HttpConfig.BASE_URL + HttpConfig.GET_BANNER)
                .params("type", type)
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<BannerBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<BannerBean>>> response) {
                        HttpData<List<BannerBean>> httpData = response.body();
                        if (httpData.getCode() == HttpConfig.OK) {
                            mView.updateUI(httpData.getData());

                        }
                    }
                });
    }

}

